package com.ruoyi.web.controller.docs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.docs.domain.dto.ArticleTreeDto;
import com.ruoyi.docs.domain.dto.MpArticleCommand;
import com.ruoyi.docs.service.IBizColumnService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.docs.domain.BizArticle;
import com.ruoyi.docs.service.IBizArticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 栏目信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-05
 */
@RestController
@RequestMapping("/docs/article")
public class BizArticleController extends BaseController
{
    @Autowired
    private IBizArticleService bizArticleService;

    @Autowired
    private IBizColumnService bizColumnService;

    /**
     * 查询栏目信息列表
     */
    @PreAuthorize("@ss.hasPermi('docs:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizArticle bizArticle)
    {
        startPage();
        List<BizArticle> list = bizArticleService.selectBizArticleList(bizArticle);
        return getDataTable(list);
    }

    /**
     * 导出栏目信息列表
     */
    @PreAuthorize("@ss.hasPermi('docs:article:export')")
    @Log(title = "栏目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizArticle bizArticle)
    {
        List<BizArticle> list = bizArticleService.selectBizArticleList(bizArticle);
        ExcelUtil<BizArticle> util = new ExcelUtil<BizArticle>(BizArticle.class);
        util.exportExcel(response, list, "栏目信息数据");
    }

    /**
     * 获取栏目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('docs:article:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return success(bizArticleService.selectBizArticleByArticleId(articleId));
    }

    /**
     * 新增栏目信息
     */
    @PreAuthorize("@ss.hasPermi('docs:article:add')")
    @Log(title = "栏目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizArticle bizArticle)
    {
        bizArticle.setCreateBy(getUsername());
        return toAjax(bizArticleService.insertBizArticle(bizArticle));
    }

    /**
     * 修改栏目信息
     */
    @PreAuthorize("@ss.hasPermi('docs:article:edit')")
    @Log(title = "栏目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizArticle bizArticle)
    {
        bizArticle.setUpdateBy(getUsername());
        return toAjax(bizArticleService.updateBizArticle(bizArticle));
    }
    @PreAuthorize("@ss.hasPermi('docs:article:edit')")
    @Log(title = "栏目信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeArticleStatus")
    public AjaxResult changeArticleStatus(@RequestBody BizArticle bizArticle)
    {
        bizArticle.setUpdateBy(getUsername());
        return toAjax(bizArticleService.updateBizArticle(bizArticle));
    }
    /**
     * 删除栏目信息
     */
    @PreAuthorize("@ss.hasPermi('docs:article:remove')")
    @Log(title = "栏目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(bizArticleService.deleteBizArticleByArticleIds(articleIds));
    }
    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('docs:article:list')")
    @GetMapping("/columnTree/{type}")
    public AjaxResult deptTree(@PathVariable("type") Long type)
    {
        return success(bizColumnService.selectColumnTreeList(type));
    }
    // @PreAuthorize("@ss.hasPermi('docs:activity:getTree')")
    @Log(title = "信息列表", businessType = BusinessType.EXPORT)
    @PostMapping("/getArticleTree")
    public AjaxResult getTree(@RequestBody ArticleTreeDto articleTreeDto)
    {
        return  success(bizArticleService.getTree(articleTreeDto));
    }

    @PreAuthorize("@ss.hasPermi('docs:article:add')")
    @Log(title = "获取公众号文章", businessType = BusinessType.INSERT)
    @PostMapping("/getMpArticle")
    public AjaxResult getMpArticle(@RequestBody MpArticleCommand mpArticle)
    {
        return success(bizArticleService.getMpArticle(mpArticle));
    }
}
